package main

import (
	"fmt"
	"time"
)

func main() {
	p := fmt.Println
	now := time.Now()  // 获取当前local Time实例
	p(now)


	then := time.Date(
		2020, 12, 8, 20, 34, 58, 651387237, time.Local)
	p(then)

	p(then.Year())
	p(then.Month())
	p(then.Day())
	p(then.Hour())
	p(then.Minute())
	p(then.Second())
	p(then.Nanosecond())
	p(then.Location())

	p(then.Weekday())

	p(then.Before(now))
	p(then.After(now))
	p(then.Equal(now))

	// 时间间隔， returns the duration t-u
	// func (t Time) Sub(u Time) Duration
	diff := now.Sub(then)
	p(diff)

	p(diff.Hours())
	p(diff.Minutes())
	p(diff.Seconds())
	p(diff.Nanoseconds())

	// func (t Time) Add(d Duration) Time
	// Add returns the time t+d.
	_, _ = p(then.Add(diff))  // 用add 将时间后移一个时间段，或者用一个 - 来将时间前移一个时间段
	p(then.Add(-diff))




}
